/*
 * knn.cc
 *
 *  Created on: Dec 16, 2014
 *      Author: root
 */
/******************************************************************************************************************/
#include <string.h>
#include <math.h>
#include "../util/global.h"
#include "knn.h"
/******************************************************************************************************************/
void KNN::Classify(TcpStat* stat) {
	TcpRecord r(stat);
	TCP_VEC::iterator it;
	double min_dis = MAX_TCP_EU_DIS;
	TcpRecord* min_r = NULL;
	for (it = g_tcp_v.begin(); it != g_tcp_v.end(); it++) {
		double tmp = r.GetEuDis(*it);
		if (min_dis > tmp) {
			min_dis = tmp;
			min_r = *it;
		}
		if (min_dis > TCP_EU_DIS_MAX || r.GetCosDis(min_r) < TCP_COS_DIS_MAX) {
			stat->label[0] = 0;
		}
		stat->SetLabel(min_r->label);
	}
}
void KNN::Classify(UdpStat* stat) {
	UdpRecord r(stat);
	UDP_VEC::iterator it;
	double min_dis = MAX_UDP_EU_DIS;
	UdpRecord* min_r = NULL;
	for (it = g_udp_v.begin(); it != g_udp_v.end(); it++) {
		double tmp = r.GetEuDis(*it);
		if (min_dis > tmp) {
			min_dis = tmp;
			min_r = *it;
		}
		if (min_dis > UDP_EU_DIS_MAX || r.GetCosDis(min_r) < UDP_COS_DIS_MAX) {
			stat->label[0] = 0;
		}
		stat->SetLabel(min_r->label);
	}
}
/******************************************************************************************************************/
